/**
 * file
 */
package com.tdkj.action.front.member.seller.sell;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.opensymphony.xwork2.ActionContext;
import com.tdkj.action.BaseAction;
import com.tdkj.model.shop.BeanOrder;
import com.tdkj.model.shop.BeanOrderItem;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.shop.IBeanOrderService;
import com.tdkj.util.PublicConfing;

public class GoodOrderAction extends BaseAction {

	private Long userId;
	private Long orderId;
	
	private List<BeanOrderItem> items;
	private List<BeanOrder> orders;
	
	private Integer state ;
	
	private IBeanOrderService orderService;
	
	public String execute(){
		BeanUser user  = (BeanUser)ActionContext.getContext().getSession().get(PublicConfing.MEMBER_MEMBWE_OBJ_STRING_CONFIG);
		Long userId = user.getId();
		if(state != null && !"".equals(state)){
			Criteria criteria = this.createCriteria(BeanOrder.class)
			.add(Restrictions.eq("seller", orderService.findById(userId, BeanUser.class)))
			.add(Restrictions.eq("state", state))
			.addOrder(Order.asc("createTime"));
			this.queryByPage(criteria, "goodOrderAction.action", 10);
		}else{
			Criteria criteria = this.createCriteria(BeanOrder.class)
			.add(Restrictions.eq("seller", orderService.findById(userId, BeanUser.class)))
			.addOrder(Order.asc("createTime"));
			this.queryByPage(criteria, "goodOrderAction.action", 10);
		}
		return "success";
	}
	
	public String orderDelivery(){
		BeanUser user  = (BeanUser)ActionContext.getContext().getSession().get(PublicConfing.MEMBER_MEMBWE_OBJ_STRING_CONFIG);
		Long userId = user.getId();
		orderService.createDelivery(userId, orderId);
		
		return execute();
	}

	/**
	 * @return the userId
	 */
	public Long getUserId() {
		return userId;
	}

	/**
	 * @param userId the userId to set
	 */
	public void setUserId(Long userId) {
		this.userId = userId;
	}

	/**
	 * @return the items
	 */
	public List<BeanOrderItem> getItems() {
		return items;
	}

	/**
	 * @param items the items to set
	 */
	public void setItems(List<BeanOrderItem> items) {
		this.items = items;
	}
	
	/**
	 * @return the orders
	 */
	public List<BeanOrder> getOrders() {
		return orders;
	}

	/**
	 * @param orders the orders to set
	 */
	public void setOrders(List<BeanOrder> orders) {
		this.orders = orders;
	}

	/**
	 * @param orderService the orderService to set
	 */
	@Resource
	public void setOrderService(IBeanOrderService orderService) {
		this.orderService = orderService;
	}

	/**
	 * @return the state
	 */
	public Integer getState() {
		return state;
	}

	/**
	 * @param state the state to set
	 */
	public void setState(Integer state) {
		this.state = state;
	}

	/**
	 * @return the orderId
	 */
	public Long getOrderId() {
		return orderId;
	}

	/**
	 * @param orderId the orderId to set
	 */
	public void setOrderId(Long orderId) {
		this.orderId = orderId;
	}
	
	
}
